package com.qhg.saas_server.controller;

import com.github.pagehelper.PageInfo;
import com.qhg.saas_server.empty.Result;
import com.qhg.saas_server.pojo.Department;
import com.qhg.saas_server.service.impl.DepartmentServiceImpl;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/department")
public class DepartmentController {

    @Autowired
    DepartmentServiceImpl departmentService;

    /*搜索部门*/
    @PostMapping("/SelectAllDepartment")
    public Result SelectAllDepartment(Integer pageNum,Integer pageSize){
        PageInfo pageInfo = departmentService.SelectAllDepartment(pageNum,pageSize);
        return Result.success(pageInfo);
    }
    /*根据ID搜索部门*/
    @GetMapping("/SelectDyId")
    public Result SelectDyId(Integer departId){
        Department department = departmentService.SelectDyId(departId);
        return Result.success(department);
    }
    /*插入部门*/
    @PostMapping("/InsertDepartment")
    public Result InsertDepartment(@RequestBody Department department){
        System.out.println(department);
        departmentService.InsertDepartment(department);
        return Result.buildSuccess();
    }
    /*修改部门状态*/
    @PostMapping("/UpdateDepartmentStatus")
    public Result UpdateDepartmentStatus(Integer departStatus,Integer departId){
        departmentService.UpdateDepartmentStatus(departStatus,departId);
        return Result.buildSuccess();
    }
    /*通过Id修改部门信息*/
    @PostMapping("/UpdataDepartmentById")
    public Result UpdataDepartmentById(@RequestBody Department department){
        departmentService.UpdataDepartmentById(department);
        return Result.buildSuccess();
    }
    /*通过Id删除部门*/
    @GetMapping("/DeleteDepartmentById")
    public Result DeleteDepartmentById(Integer departId){
        departmentService.DeleteDepartmentById(departId);
        return Result.buildSuccess();
    }
}
